﻿using Fuse8.ContentManagementFramework.Domain;
using Fuse8.DomainFramework.Common;
using Fuse8.DomainFramework.ValidationService;

namespace Fuse8.ContentManagementFramework.BizFacade.Validation
{
    public class CmsEntityMetaValidationService : BaseEntityValidationService<CmsEntityMeta>
    {
        public override ValidationResult Validate(CmsEntityMeta entityObject, ValidationActionType actionType)
        {
            ValidationResult result = null;

            if (actionType != ValidationActionType.Delete)
            {
                //todo: check value types too
                if (entityObject.EntityMetaFieldLink.IsRequired && string.IsNullOrEmpty(entityObject.EntityMetaValue))
                {
                    result = new ValidationResult()
                                 {
                                     IsValid = false,
                                     ValidationMessage =
                                         string.Format("Meta Field '{0}' is required",
                                                       entityObject.EntityMetaFieldLink.DisplayLabel)
                                 };
                }
            }
            return result ?? base.Validate(entityObject, actionType);
        }
    }
}